/**
 * 
 * 选中一个基准值，将数组分为比基准值大和比基准值小的两个数组，然后再对两个数组进行排序 
 */
function quickSort(arr) {
  if (arr.length <= 1) return arr
  let midIndex = Math.floor(arr.length / 2)
  let midVal = arr.splice(midIndex, 1)[0]
  let left = []
  let right = []
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] > midVal) left.push(arr[i])
    else right.push(arr[i])
  }
  return [...quickSort(left), midVal, ...quickSort(right)]
}

console.log(quickSort([4, 2, 5, 3, 6, 1, 3, 8]));